package Zoo.handler;


import Zoo.entity.ZooparkEntity;
import Zoo.impl.ZoomenServiceImpl;
import Zoo.service.ZoomenService;
import Zoo.view.zoomanview.UpdateZooparkView1;
import Zoo.view.zoomanview.ZoomenView;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * 动物饲养员的修改园区信息界面处理类
 */
public class UpdateZooparkView1Handler implements ActionListener {
    private UpdateZooparkView1 updateZooparkView1;
    private ZoomenView zoomenView;


    public UpdateZooparkView1Handler(UpdateZooparkView1 updateZooparkView1, ZoomenView zoomenView) {
        this.updateZooparkView1 = updateZooparkView1;
        this.zoomenView = zoomenView;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        JButton jButton = (JButton) e.getSource();
        String text = jButton.getText();
        if ("修改".equals(text)) {
            ZoomenService zoomenService = new ZoomenServiceImpl();
            ZooparkEntity zooparkEntity = updateZooparkView1.buildUpdatedZooparkEntity();
            boolean updateResult = zoomenService.update(zooparkEntity);
            if (updateResult) {
                //重新加载表格查到最新数据
                zoomenView.reloadTable();
                updateZooparkView1.dispose();
            } else {
                JOptionPane.showMessageDialog(updateZooparkView1, "修改失败");

            }

        }
    }

}
